package com.jxust.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jxust.mapper.StuMapper;
import com.jxust.pojo.PageResult;
import com.jxust.pojo.Student;
import com.jxust.pojo.StudentQueryParam;
import com.jxust.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StuServiceImpl implements StuService {

    @Autowired
    private StuMapper stuMapper;

    @Override
    public PageResult<Student> page(StudentQueryParam studentQueryParam) {
        //1.设置分页参数
        PageHelper.startPage(studentQueryParam.getPage(),studentQueryParam.getPageSize());
        //2.执行查询
        List<Student> studentList = stuMapper.list(studentQueryParam);
        //3. 解析查询结果，并封装
        Page<Student> p=(Page<Student>)studentList;
        return new PageResult<Student>(p.getTotal(), p.getResult());
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        //1. 批量删除学生基本信息
        stuMapper.deleteByIds(ids);
    }

    @Override
    public void save(Student student) {
        //1.保存员工 基本信息
         student.setCreateTime(LocalDateTime.now());
         student.setUpdateTime(LocalDateTime.now());
         stuMapper.insert(student);
    }
}
